import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue';
import postCssPxToRem from "postcss-pxtorem";
import { resolve } from 'path';
import Components from 'unplugin-vue-components/vite';
import { VantResolver } from 'unplugin-vue-components/resolvers';


export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()],
    })

  ],
  //配置路径别名
  //配置@路径别名
  resolve: {
    alias: {
      '@': resolve(__dirname, "src"),
    },
    // extensions: [".ts", ".vue", ".js", ".jsx", ".tsx"], // 导入时想要省略的扩展名列表。
  },
  css: {
    preprocessorOptions: {
      less: {
      }
    },
    postcss: {
      plugins: [
        postCssPxToRem({
          rootValue: 37.5, // 1rem的大小
          propList: ['*'], // 需要转换的属性，这里选择全部都进行转换
        })
      ]
    }
  },
  server: {
    localhost: '0.0.0.0',
    port: 8081,
    open: true,
    proxy: {
      '/sph': {
        target: 'http://gmall-h5-api.atguigu.cn',//这个用不了，就用下面的
        // target: 'http://sph-h5-api.atguigu.cn',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/sph/, ''),
      },

      '/wy': {
        target: 'https://m.you.163.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/wy/, ''),
      },
    }

  }
})
